﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlTypes;
using System.Linq;
using System.Text;


namespace nadModel.AutoFeed
{
    public partial class AutoFeedEntityProcess : AbstractEntityProcess
    {

        public override AbstractEntity[] PackEntity(object obj)
        {
            //pack entries
            List<AutoFeedEntity> entryList = new List<AutoFeedEntity>();

            AutoFeedEntity entry;
            try
            {
                DataTable dt = (DataTable)obj;
                if (dt == null)
                {
                    return null;
                }

                foreach (DataRow item in dt.Rows)
                {
                    entry = new AutoFeedEntity();
                    entry.IssueNo = item[AutoFeedEntity.ISSUE_NO].ToString();
                    entry.JobNum = item[AutoFeedEntity.JOB_NUM].ToString();
                    entry.AssemblySeq = item[AutoFeedEntity.ASSEMBLY_SEQ].ToString();
                    entry.MtlSeq = item[AutoFeedEntity.MTL_SEQ].ToString();
                    entry.MtlPartNum = item[AutoFeedEntity.MTL_PARTNUM].ToString();
                    entry.OldPartNum = item[AutoFeedEntity.OLD_PARTNUM].ToString();
                    entry.PartDescription = item[AutoFeedEntity.PART_DESCRIPTION].ToString();
                    entry.RequiredQty = Convert.ToDecimal(item[AutoFeedEntity.REQUIRED_QTY].ToString());
                    entry.ApplyQty = Convert.ToDecimal(item[AutoFeedEntity.APPLY_QTY].ToString());
                    entry.Schedule = string.IsNullOrEmpty(item[AutoFeedEntity.SCHEDULE].ToString()) ? null : DateTime.Parse(item[AutoFeedEntity.SCHEDULE].ToString()).ToString("yyyy-MM-dd");
                    entry.ScheduleNo = item[AutoFeedEntity.SCHEDULENO].ToString();
                    entry.SendStatus = item[AutoFeedEntity.SEND_STATUS].ToString();
                    entry.CompleteStatus = item[AutoFeedEntity.COMPLETE_STATUS].ToString();
                    entry.ExecuStatus = item[AutoFeedEntity.EXECU_STATUS].ToString();
                    entryList.Add(entry);
                }
            }
            catch (Exception ex)
            {
                Log("ERROR: error packing entity", LogLevel.FATAL);
                Log(ex.ToString(), LogLevel.FATAL);
                throw ex;
            }
            return (AbstractEntity[])entryList.ToArray();

        }
    }
}
